package com.zzyl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONUtil;
import org.junit.Test;
import org.springframework.http.HttpHeaders;

import java.util.Map;

public class Httptest {
    @Test
    /**
     * 测试https的get请求
     */
    public void httpsimple() {
        /**
         * 简单请求
         */
       /* String s = HttpUtil.get("https://www.baidu.com");
        System.out.println(s);*/
        //高级请求
        HttpResponse execute = HttpUtil.createGet("https://www.baidu.com").execute();
       if (execute.isOk()){
           System.out.println(execute.body());
       }
    }
    /**
     * 测试https的post请求
     */
    @Test
    public void httpsimplepost() {
        Map<String, String> username = Map.of("username", "admin", "password", "admin123",
                "code", "16", "uuid", "692bbf3167a44bbca3a1af484bb0ba0c");
        String reqbody = JSONUtil.toJsonStr(username);

        String post = HttpUtil.post("http://localhost:8080/login", reqbody);
        System.out.println( post);
    }
    @Test
    /**
     * 测试护理项目的get请求
     */
    public void httpsimpleget() {

        HttpResponse execute = HttpUtil.createGet("http://localhost:8080/serve/project/list")
                .form("pageNum", 1)
                .form("pageSize", 5)
                .header(HttpHeaders.AUTHORIZATION, "Bearer eyJhbGciOiJIUzUxMiJ9.eyJsb2dpbl91c2VyX2tleSI6Ijg3Yjc0NTA2LTc3ZDYtNGNiOS05NDUwLTJlNmM4YmM3NTNlZCJ9.2TlbKWRwR0HECd12g3mnlVw9wznZlPdnXrY6eulcX9deHhVN5PwGfnRSa-gntgTMzzehZJVV5b27QIhlg_Y-hg")
                .execute();
        if (execute.isOk()){
            String body = execute.body();
            System.out.println(body);
        }
    }
}
